package com.gt.controller.system;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gt.common.CommonConstant;
import com.gt.entity.base.DataMessage;
import com.gt.entity.project.Project;
import com.gt.entity.projectJsdebug.ProjectJsdebug;
import com.gt.entity.projectJsdebugDetails.ProjectJsdebugDetails;
import com.gt.entity.projectMember.ProjectMember;
import com.gt.entity.user.User;
import com.gt.service.project.ProjectService;
import com.gt.service.projectJsdebug.ProjectJsdebugService;
import com.gt.service.projectJsdebugDetails.ProjectJsdebugDetailsService;
import com.gt.service.projectMember.ProjectMemberService;
import com.gt.service.user.UserService;
import com.gt.utils.ApikeyUtil;
import com.gt.utils.EmailUtil2;
import com.gt.utils.TokenUtils;
import com.gt.utils.captcha.Captcha;
import com.gt.utils.captcha.GifCaptcha;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;


@Controller
@SuppressWarnings("all")
public class SystemController {
    private static Logger logger = Logger.getLogger(SystemController.class);

    @Autowired
    private UserService userService;//用户
    @Autowired
    private JavaMailSender javaMailSender;
    @Value("${spring.mail.sender}")
    private String sender;
    @Autowired
    private TokenUtils tokenUtils;
    @Autowired
    private ProjectService projectService;
    @Autowired
    private ProjectMemberService projectMemberService;
    @Autowired
    private ProjectJsdebugService projectJsdebugService;
    @Autowired
    private ProjectJsdebugDetailsService projectJsdebugDetailsService;

    /**
     * 首页
     * @return why
     * @throws Exception
     */
    @GetMapping("sys/first")
    public String toFirstPage() throws Exception{
        return "system/first";
    }

    /**
     * 登录页面
     * @return why
     * @throws Exception
     */
    @GetMapping("sys/toLoginPage")
    public String toLoginPage(
            @RequestParam(required = false, value = "userName") String userName,
            Model model
    ) throws Exception{
        model.addAttribute("userName", StringUtils.isEmpty(userName)?"1":userName);
        return "system/login";
    }

    /**
     * 主页
     * @return
     * @throws Exception
     */
    @GetMapping("sys/index")
    public String index(@RequestParam(required = true, value = "access_token") String access_token) throws Exception{
        return "system/index";
    }

    /**
     * 控制台
     * @return
     * @throws Exception
     */
    @GetMapping("sys/center")
    public String console(@RequestParam(required = true, value = "access_token") String access_token, Model model) throws Exception{
        if(!StringUtils.isEmpty(access_token)) {
            String userName = tokenUtils.getUsernameFromToken(access_token);
            List<Project> projectList = this.projectService.querySelectByUserName(userName);
            model.addAttribute("projectList", projectList);
        }else{
            logger.info("token为空");
        }
        return "system/common/common_center";
    }

    /**
     * 项目列表
     * @return
     * @throws Exception
     */
    @GetMapping("sys/project_list")
    public String projectList() throws Exception{
        return "system/project_list";
    }

    /**
     * 添加项目
     * @return
     * @throws Exception
     */
    @GetMapping("sys/project_add")
    public String projectAdd(Model model) throws Exception{
        String apikey = ApikeyUtil.getRandomString(64);
        StringBuilder sb = new StringBuilder();
        sb.append("<script src=\"");
        sb.append(CommonConstant.jsurl.getCode().toString());
        sb.append("\" \napikey=\"");
        sb.append(apikey);
        sb.append("\">");
        sb.append("</script>");
        model.addAttribute("js", sb.toString());
        model.addAttribute("jsurl", CommonConstant.jsurl.getCode().toString());
        model.addAttribute("apikey", apikey);

        return "system/project_add";
    }

    /**
     * 创建项目
     * @param access_token
     * @param projectName
     * @param projectLanguage
     * @param projectApikey
     * @param projectJsUrl
     * @param email1
     * @param email2
     * @param email3
     * @param email4
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("sys/addProject")
    public DataMessage addProject(
            @RequestParam(required = true, value = "access_token") String access_token,
            @RequestParam(required = true, value = "projectName") String projectName,
            @RequestParam(required = true, value = "projectLanguage") String projectLanguage,
            @RequestParam(required = true, value = "projectApikey") String projectApikey,
            @RequestParam(required = true, value = "projectJsUrl") String projectJsUrl,
            @RequestParam(required = false, value = "email1") String email1,
            @RequestParam(required = false, value = "email2") String email2,
            @RequestParam(required = false, value = "email3") String email3,
            @RequestParam(required = false, value = "email4") String email4
    ) throws Exception{
        DataMessage dm = new DataMessage();
        String userName = tokenUtils.getUsernameFromToken(access_token);
        if(StringUtils.isEmpty(userName)){
            dm.setResult((int)CommonConstant.失败.getCode());
            dm.setData(null);
            dm.setMessage("用户不存在");
        }else{
            User query = new User();
            query.setUserName(userName);
            List<User> queryList = this.userService.queryList(query);
            if(null == queryList || queryList.isEmpty()){
                dm.setResult((int)CommonConstant.失败.getCode());
                dm.setData(null);
                dm.setMessage("用户不存在");
            }else{
                Project add = new Project();
                add.setProjectName(projectName);
                add.setProjectLanguage(1);//js
                add.setProjectApikey(projectApikey);
                add.setProjectJsUrl(projectJsUrl);
                add.setUserId(queryList.get(0).getId());
                add.setDebugNum(0);
                add.setCreateTime(System.currentTimeMillis());
                add.setUpdateTime(System.currentTimeMillis());
                Long projectId = this.projectService.add(add);
                new Thread(() -> {
                    HashSet<String> email = new HashSet<String>();
                    email.add(userName);//创建者
                    if(!StringUtils.isEmpty(email1)){
                        email.add(email1);
                    }
                    if(!StringUtils.isEmpty(email2)){
                        email.add(email2);
                    }
                    if(!StringUtils.isEmpty(email3)){
                        email.add(email3);
                    }
                    if(!StringUtils.isEmpty(email4)){
                        email.add(email4);
                    }
                    for(String em : email){
                        ProjectMember pm = new ProjectMember();
                        pm.setMemberEmail(em);
                        pm.setIsAdmin(em.equals(userName)?1:2);//1：创建者  2：参与者
                        pm.setState((int)CommonConstant.启用.getCode());
                        pm.setProjectId(projectId);
                        pm.setIsRemind(1);
                        pm.setCreateTime(System.currentTimeMillis());
                        pm.setUpdateTime(System.currentTimeMillis());
                        this.projectMemberService.add(pm);
                    }
                    SystemController.notifyMember(email, queryList.get(0).getNickName(), queryList.get(0).getUserName(), projectName, sender, javaMailSender);
                }).start();
                dm.setResult((int)CommonConstant.成功.getCode());
                dm.setData(projectId);
                dm.setMessage("添加成功");
            }
        }
        return dm;
    }

    /**
     * 通知项目成员
     * @param email
     */
    public static void notifyMember(HashSet<String> email, String inviterName, String inviterEmail, String projectName, String sender, JavaMailSender javaMailSender){
        StringBuilder sb = new StringBuilder();
        sb.append("<html>");
        sb.append("<body>");
        sb.append("<center>");
        sb.append("<div style=\"margin-top:0px;background-color: #F09B22;width: 70%; height: 40%;padding: 10% 20%;\">");
        sb.append("<p><img src=\"http://39.106.249.147:9999/css/assets/img/logo_red.png\" style=\"width: 250px; height: 80px;\" /></p>");
        //绿萝(yangxing@gtexpress.cn)邀请您加入超级绿萝项目。该链接在24小时之内有效。
        sb.append("<p style=\"color: white\">您好，"+inviterName+"("+inviterEmail+")邀请您加入"+projectName+"项目。</p>");
        sb.append("<p style=\"background-color:#3498db;border-radius:10px;width: 150px; height: 50px; line-height: 50px; border: none;color:white;margin-top: 50px;\">");
        sb.append("<a href=\""+CommonConstant.loginurl.getCode().toString()+"\" style=\"text-decoration:none;color:white;\">去登录</a>");
        sb.append("</p>");
        sb.append("</div>");
        sb.append("</center>");
        sb.append("</body>");
        sb.append("</html>");
        new Thread(() -> {
            try {
                boolean flag = EmailUtil2.sendEmail(1, "gtdebug", StringUtils.join(email,","), "加入邀请", sb.toString());
                if(!flag){
                    EmailUtil2.sendEmail(2, "gtdebug", StringUtils.join(email,","), "加入邀请", sb.toString());
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }


    /**
     * 团队信息
     * @return
     * @throws Exception
     */
    @GetMapping("sys/team_info")
    public String teamInfo(
            @RequestParam(required = true, value = "access_token") String access_token,
            Model model)
            throws Exception{
        User query = new User();
        query.setUserName(tokenUtils.getUsernameFromToken(access_token));
        List<User> userList = this.userService.queryList(query);
        if(null != userList && !userList.isEmpty()){
            model.addAttribute("teamName",userList.get(0).getTeamName());
            model.addAttribute("createTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(userList.get(0).getCreateTime()));
        }

        return "system/team_info";
    }

    /**
     * 成员管理
     * @return
     * @throws Exception
     */
    @GetMapping("sys/member_management")
    public String memberManagement() throws Exception{
        return "system/member_management";
    }

    /**
     * 获取验证码
     */
    @GetMapping("sys/captcha")
    @ResponseBody
    public void executeCaptcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/gif");
        Captcha captcha = new GifCaptcha(100,40,4);
        HttpSession session = request.getSession(true);
//	        Captcha captcha = new SpecCaptcha(146,33,4);
        //输出
        captcha.out(response.getOutputStream());
        //存入Session
        session.setAttribute("captcha",captcha.text().toLowerCase());
    }

    /**
     * 注册
     * @param userName
     * @param password
     * @param teamName
     * @param nickName
     * @param captcha
     * @param request
     * @return
     * @throws Exception
     */
    @PostMapping("sys/register")
    @ResponseBody
    public DataMessage register(
            @RequestParam(required = true, value = "userName") String userName,
            @RequestParam(required = true, value = "password") String password,
            @RequestParam(required = true, value = "teamName") String teamName,
            @RequestParam(required = true, value = "nickName") String nickName,
            @RequestParam(required = true, value = "captcha") String captcha,
            HttpServletRequest request
            ) throws Exception{
        DataMessage dm = new DataMessage();
        if(request.getSession().getAttribute("captcha") != null && request.getSession().getAttribute("captcha").toString().equalsIgnoreCase(captcha)){
            User query = new User();
            query.setUserName(userName);
            query.setEnable((int)CommonConstant.启用.getCode());
            List<User> queryList = this.userService.queryList(query);
            if(queryList != null && !queryList.isEmpty()){
                dm.setResult((int)CommonConstant.失败.getCode());
                dm.setData(null);
                dm.setMessage("该邮箱已注册，请去登录!");
            }else{
                User u = new User();
                u.setUserName(userName);
                u.setNickName(nickName);
                u.setPassword(password);
                u.setTeamName(teamName);
                u.setCreateTime(System.currentTimeMillis());
                u.setUpdateTime(System.currentTimeMillis());
                u.setEnable((int)CommonConstant.启用.getCode());
                u.setLastPasswordChange(System.currentTimeMillis());
                u.setRoleId((int)CommonConstant.普通用户.getCode());
                this.userService.add(u);
                dm.setResult((int)CommonConstant.成功.getCode());
                dm.setData(null);
                dm.setMessage("注册成功");
            }
        }else{
            dm.setResult((int)CommonConstant.失败.getCode());
            dm.setData(null);
            dm.setMessage("验证码错误");
        }
        return dm;
    }

    @PostMapping("sys/forget")
    @ResponseBody
    public DataMessage forget(
            @RequestParam(required = true, value = "userName") String userName
    ) throws Exception{
        DataMessage dm = new DataMessage();
        User query = new User();
        query.setUserName(userName);
        List<User> queryList = this.userService.queryList(query);
        if(null == queryList && queryList.isEmpty()){
            dm.setResult((int)CommonConstant.失败.getCode());
            dm.setData(null);
            dm.setMessage("该邮箱未来注册!");
        }else{
            //发送邮件

            String forgetUrl = CommonConstant.loginurl.getCode()+"?userName="+userName;
            StringBuilder sb = new StringBuilder();
            sb.append("<html>");
            sb.append("<body>");
            sb.append("<center>");
            sb.append("<div style=\"margin-top:0px;background-color: #F09B22;width: 70%; height: 40%;padding: 10% 20%;\">");
            sb.append("<p><img src=\"http://39.106.249.147:9999/css/assets/img/logo_red.png\" style=\"width: 250px; height: 80px;\" /></p>");
            sb.append("<p style=\"color: white\">您好，请尽快重置账户密码。</p>");
            sb.append("<p style=\"background-color:#3498db;border-radius:10px;width: 150px; height: 50px; line-height: 50px; border: none;color:white;margin-top: 50px;\">");
            sb.append("<a href=\""+forgetUrl+"\" style=\"text-decoration:none;color:white;\">重置密码</a>");
            sb.append("</p>");
            sb.append("</div>");
            sb.append("</center>");
            sb.append("</body>");
            sb.append("</html>");
            new Thread(() -> {
                try {
                    boolean flag = EmailUtil2.sendEmail(1, "gtdebug", userName, "gtdebug重置密码", sb.toString());
                    if(!flag){
                        EmailUtil2.sendEmail(2, "gtdebug", userName, "gtdebug重置密码", sb.toString());
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }).start();
        }
        return dm;
    }

    /**
     * 重置密码
     * @param userName      用户名
     * @param password      密码
     * @return
     * @throws Exception
     */
    @PostMapping("sys/resetPassword")
    @ResponseBody
    public DataMessage resetPassword(
            @RequestParam(required = true, value = "userName") String userName,
            @RequestParam(required = true, value = "password") String password
    ) throws Exception{
        DataMessage dm = new DataMessage();
        User query = new User();
        query.setUserName(userName);
        List<User> queryList = this.userService.queryList(query);
        if(null != queryList && !queryList.isEmpty()){
            User edit = new User();
            edit.setId(queryList.get(0).getId());
            edit.setPassword(password);
            edit.setLastPasswordChange(System.currentTimeMillis());
            edit.setUpdateTime(System.currentTimeMillis());
            this.userService.edit(edit);
            dm.setResult((int)CommonConstant.成功.getCode());
            dm.setData(null);
            dm.setMessage("重置成功！");
        }else{
            dm.setResult((int)CommonConstant.失败.getCode());
            dm.setData(null);
            dm.setMessage("账户不存在！");
        }
        return dm;
    }

    /**
     * 模拟错误
     * @return
     * @throws Exception
     */
    @GetMapping("sys/a")
    public String a() throws Exception{
        return "a";
    }

    /**
     * 项目列表
     * @param request
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("sys/loadProjectList")
    public Map<Object, Object> loadProjectList(HttpServletRequest request) throws Exception{
        // 直接返回前台
        String draw = request.getParameter("draw");
        // 数据起始位置
        String startIndex = request.getParameter("startIndex");
        // 每页显示的条数
        String pageSize = request.getParameter("pageSize");
        // 获取排序字段
        String name = request.getParameter("orderColumn");
        //用户token
        String access_token = request.getParameter("access_token");
        if(name == null){
            name = "project_name";
        }
        int pageNum = Integer.parseInt(startIndex)/Integer.parseInt(pageSize);
        pageNum = pageNum<1?1:++pageNum;
        PageHelper.startPage(pageNum, Integer.parseInt(pageSize),"id desc");
        List<Project> result = this.projectService.querySelectByUserName(tokenUtils.getUsernameFromToken(access_token));
        PageInfo<Project> info = new PageInfo<>(result);
        Map<Object, Object> res = new HashMap<>();
        res.put("pageData", info.getList());
        res.put("total", info.getTotal());
        res.put("draw", draw);
        logger.info("projectList="+res);
        return res;
    }

    /**
     * 加载错误列表
     * @param request
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("sys/loadProjecErrorList")
    public Map<Object, Object> loadProjecErrorList(HttpServletRequest request) throws Exception{
        // 直接返回前台
        String draw = request.getParameter("draw");
        // 数据起始位置
        String startIndex = request.getParameter("startIndex");
        // 每页显示的条数
        String pageSize = request.getParameter("pageSize");
        //用户token
        String access_token = request.getParameter("access_token");
        // 获取排序字段
        String name = request.getParameter("orderColumn");
        if(name == null){
            name = "project_id";
        }
        // 获取排序方式
        String sort = request.getParameter("orderDir");
        if (sort == null) {
            sort = "asc";
        }
        // 查询条件
        String project_id = request.getParameter("projectId");
        ProjectJsdebug pj = new ProjectJsdebug();
        if(!StringUtils.isEmpty(project_id)){
            pj.setProjectId(Long.parseLong(project_id));
        }else{
            pj.setProjectId(0L);
        }
        int pageNum = Integer.parseInt(startIndex)/Integer.parseInt(pageSize);
        pageNum = pageNum<1?1:++pageNum;
        PageHelper.startPage(pageNum, Integer.parseInt(pageSize), "id desc");
        List<ProjectJsdebug> result = this.projectJsdebugService.queryList(pj);
        PageInfo<ProjectJsdebug> info = new PageInfo<>(result);
        Map<Object, Object> res = new HashMap<>();
        res.put("pageData", info.getList());
        res.put("total", info.getTotal());
        res.put("draw", draw);
        logger.info("projectList="+res);
        return res;
    }

    /**
     * 加载项目成员列表
     * @param projectId
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("sys/loadMemeberList/{projectId}")
    public DataMessage loadMemeberList(
            @PathVariable(required = true, value = "projectId") Long projectId
    ) throws Exception{
        DataMessage dm = new DataMessage();
        List<ProjectMember> projectMemberList = this.projectMemberService.querySelectMemberByProjectId(projectId);
        dm.setResult((int)CommonConstant.成功.getCode());
        dm.setData(projectMemberList);
        dm.setMessage(null);
        return dm;
    }

    /**
     * 是否提醒
     * @param id
     * @param state
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("sys/editMember/{id}/{state}")
    public DataMessage editMember(
            @PathVariable(required = true, value = "id") Long id,
            @PathVariable(required = true, value = "state") int state) throws Exception{
        DataMessage dm = new DataMessage();
        ProjectMember _edit_pm = new ProjectMember();
        _edit_pm.setId(id);
        _edit_pm.setIsRemind(state);
        this.projectMemberService.edit(_edit_pm);
        dm.setResult((int)CommonConstant.成功.getCode());
        dm.setMessage("操作成功");
        dm.setData(null);
        return dm;
    }

    /**
     * 加载错误详情
     * @param projectDebugId
     * @return
     */
    @PostMapping("sys/loadDebugDetails/{projectDebugId}")
    @ResponseBody
    public DataMessage loadDebugDetails(
            @PathVariable(required = true, value = "projectDebugId") Long projectDebugId
    ){
        DataMessage dm = new DataMessage();
        ProjectJsdebugDetails query = new ProjectJsdebugDetails();
        query.setJsDebugId(projectDebugId);
        List<ProjectJsdebugDetails> projectJsdebugDetailsList = this.projectJsdebugDetailsService.queryList(query);
        if(null != projectJsdebugDetailsList && !projectJsdebugDetailsList.isEmpty()){
            dm.setResult((int)CommonConstant.成功.getCode());
            dm.setMessage(null);
            dm.setData(projectJsdebugDetailsList.get(0));
        }else{
            dm.setResult((int)CommonConstant.失败.getCode());
            dm.setMessage("该错误不存在");
            dm.setData(null);
        }
        return dm;
    }

    /**
     * 加载chart数据
     * @param projectId
     * @return
     */
    @GetMapping("sys/loadChartData/{projectId}")
    @ResponseBody
    public List loadChartData(
            @PathVariable(required = true, value = "projectId") Long projectId
    ){
        List<HashMap> result = this.projectJsdebugService.querySelectChart(projectId);
        List<List> res = new ArrayList<>();
        if(result != null && !result.isEmpty()){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            result.forEach((HashMap item) ->{
                List temp = new ArrayList();
                try {
                    Date d = sdf.parse(item.get("day").toString());
                    temp.add(Date.UTC(d.getYear(),d.getMonth(),d.getDate(),0,0,0));
                }catch (ParseException e){
                    e.printStackTrace();
                }
                temp.add(item.get("num"));
                res.add(temp);
            });

        }else{
            List temp = new ArrayList();
            Date d = new Date();
            temp.add(Date.UTC(d.getYear(),d.getMonth(),d.getDate(),0,0,0));
            temp.add(0);
            res.add(temp);
        }
        logger.info(res);
        return res;
    }

    /**
     * 查询所有bug
     * @return
     * @throws Exception
     */
    @PostMapping("sys/getAllDebugNum")
    @ResponseBody
    public DataMessage getAllDebugNum() throws Exception{
        Integer num = this.projectJsdebugService.queyrSelectAllNum();
        DataMessage dm = new DataMessage();
        dm.setResult((int)CommonConstant.成功.getCode());
        dm.setData(num);
        dm.setMessage(null);
        return dm;
    }

    @GetMapping("sys/test")
    @ResponseBody
    public String testSendEmail(
            @RequestParam(required = true, value = "toEmail") String toEmail,
            @RequestParam(required = true, value = "type") int type) throws Exception {
        if(type == 1){
            //普通邮件
                new Thread(() -> {
                    try {

                        boolean flag = EmailUtil2.sendEmail(1, "gtdebug", toEmail, "邮件测试", "测试普通邮件");
                        if(!flag){
                            EmailUtil2.sendEmail(2, "gtdebug", toEmail, "邮件测试", "测试普通邮件");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }).start();
        }else{
            String forgetUrl = CommonConstant.loginurl.getCode().toString();
            StringBuilder sb = new StringBuilder();
            sb.append("<html>");
            sb.append("<body>");
            sb.append("<center>");
            sb.append("<div style=\"margin-top:0px;background-color: #F09B22;width: 70%; height: 40%;padding: 10% 20%;\">");
            sb.append("<p><img src=\"http://39.106.249.147:9999/css/assets/img/logo_red.png\" style=\"width: 250px; height: 80px;\" /></p>");
            sb.append("<p style=\"color: white\">尊敬的gtdebug用户您好，");
            sb.append("您的XXX项目有错误信息产生,请及时查看。");
            sb.append("</p>");
            sb.append("<p style=\"background-color:#3498db;border-radius:10px;width: 150px; height: 50px; line-height: 50px; border: none;color:white;margin-top: 50px;\">");
            sb.append("<a href=\""+forgetUrl+"\" style=\"text-decoration:none;color:white;\">查看详情</a>");
            sb.append("</p>");
            sb.append("</div>");
            sb.append("</center>");
            sb.append("</body>");
            sb.append("</html>");
            new Thread(() -> {
                try {
                    boolean flag = EmailUtil2.sendEmail(1, "gtdebug", toEmail, "邮件测试", sb.toString());
                    if(!flag){
                        EmailUtil2.sendEmail(2, "gtdebug", toEmail, "邮件测试", sb.toString());
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }).start();
        }
        return "ok";
    }

    /**
     * 404页面
     * @return
     */
    @GetMapping("sys/404")
    public String notFound(){
        return "error/404";
    }

    /**
     * 500页面
     * @return
     */
    @GetMapping("sys/500")
    public String error(){
        return "error/500";
    }

    public static void main(String[] args) throws ParseException {
//        String str = "";
//        System.out.println(StringUtils.isEmpty(str)?12:34);
//
//        StringBuilder sb = new StringBuilder();
//        sb.append("<script src=\"");
//        sb.append(CommonConstant.jsurl.getCode().toString());
//        sb.append("\" \napikey=\"");
//        sb.append(ApikeyUtil.getRandomString(64));
//        sb.append("\">");
//        sb.append("</script>");
//        System.out.println(sb.toString());

//        Map<String, Object> m = new HashMap<>();
//        User u = new User();
//        u.setId(123L);
//        m.put("1",u);
//        System.out.println(m.toString());
//        int a = 1;
//        System.out.println(++a);
//        System.out.println(a++);
        List l = new ArrayList();
        l.add("1");
        l.add("2");
        l.add("3");
        l.add("4");
        System.out.println(StringUtils.join(l,","));
//        l.forEach(item ->{
//            System.out.println(item);
//        });
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        System.out.println(sdf.parse("2018-05-13"));
        String a ="张三、李四、王五";
        System.out.println(a.split("、")[0]);





    }

}
